'
该场景为局内升级的小卡片
'

extends PanelContainer

signal selected#被选中时发送

@onready var name_label = $%NameLabel
@onready var description_label = $%DescriptionLabel

var disabe = false#防止快速点击选择多个属性

func _ready() -> void:
	self.gui_input.connect(on_input_event)
	self.mouse_entered.connect(on_mouse_entered)
	pass

#设置卡片的属性
func set_ability_upgrade(upgrade: AbilityUpgrade) -> void:
	name_label.text = upgrade.name
	description_label.text = upgrade.description 
	pass

#被创造进入场景时播放，需要外界调用，并且延迟delay调用进场动画
func play_in(delay: float = 0) -> void:
	#self.scale = Vector2.ONE * 0.5
	self.modulate = Color.TRANSPARENT#透明色
	await self.get_tree().create_timer(delay).timeout
	#self.modulate = Color.WHITE
	$AnimationPlayer.play("in")
	pass

#未被选中时播放丢弃动画
func play_discard() -> void:
	$AnimationPlayer.play("discard")


#处理卡片被点击选中
func on_input_event(event: InputEvent) -> void:
	if event.is_action_pressed("life_click") && !disabe:
		disabe = true
		$AnimationPlayer.play("selected")
		for cards in self.get_tree().get_nodes_in_group("upgrade_card"):
			if cards == self:
				continue
			cards.play_discard()
		await $AnimationPlayer.animation_finished
		selected.emit()
	pass

#鼠标进入范围时播放摇摆动画
func on_mouse_entered() -> void:
	if disabe:
		return
	$HoverAnimationPlayer.play("hover")
	pass
